load("//tools/lint:lint.bzl", "add_lint_tests")
load(
    "//tools/skylark:drake_cc.bzl",
    "drake_cc_binary",
    "drake_cc_googletest",
    "drake_cc_library",
    "drake_cc_package_library",
)
load(
    "//tools/skylark:drake_py.bzl",
    "drake_py_unittest",
)

package(default_visibility = ["//visibility:public"])

filegroup(
    name = "doxygen_input",
    srcs = [
        "contact_surface_doxygen.h",
        "penetration_doxygen.h",
        "proximity_doxygen.h",
    ] + glob([
        "images/*.png",
    ]),
    tags = ["nolint"],
    visibility = ["//doc/doxygen_cxx:__pkg__"],
)

drake_cc_package_library(
    name = "proximity",
    visibility = ["//visibility:public"],
    deps = [
        ":boxes_overlap",
        ":bv",
        ":bvh",
        ":bvh_updater",
        ":calc_obb",
        ":collision_filter",
        ":contact_surface_utility",
        ":deformable_contact_geometries",
        ":deformable_contact_internal",
        ":deformable_field_intersection",
        ":deformable_mesh_intersection",
        ":detect_zero_simplex",
        ":field_intersection",
        ":hydroelastic_internal",
        ":inflate_mesh",
        ":make_box_field",
        ":make_box_mesh",
        ":make_capsule_field",
        ":make_capsule_mesh",
        ":make_convex_field",
        ":make_convex_hull_mesh",
        ":make_convex_mesh",
        ":make_cylinder_field",
        ":make_cylinder_mesh",
        ":make_ellipsoid_field",
        ":make_ellipsoid_mesh",
        ":make_mesh_field",
        ":make_mesh_from_vtk",
        ":make_sphere_field",
        ":make_sphere_mesh",
        ":mesh_field",
        ":mesh_half_space_intersection",
        ":mesh_intersection",
        ":mesh_plane_intersection",
        ":mesh_to_vtk",
        ":mesh_traits",
        ":meshing_utilities",
        ":obj_to_surface_mesh",
        ":plane",
        ":polygon_surface_mesh",
        ":polygon_to_triangle_mesh",
        ":posed_half_space",
        ":sorted_triplet",
        ":tessellation_strategy",
        ":triangle_surface_mesh",
        ":volume_mesh",
        ":volume_mesh_refiner",
        ":volume_mesh_topology",
        ":volume_to_surface_mesh",
        ":vtk_to_volume_mesh",
    ],
)

drake_cc_library(
    name = "boxes_overlap",
    srcs = ["boxes_overlap.cc"],
    hdrs = ["boxes_overlap.h"],
    copts = [
        # Hard coding optimization keeps performance high in debug.  If you are
        # a developer trying to debug these files, you might want to comment
        # this out temporarily.
        "-O2",
    ],
    deps = [
        "//math:geometric_transform",
        "@eigen",
    ],
    implementation_deps = [
        "//common:hwy_dynamic",
        "@highway_internal//:hwy",
    ],
)

drake_cc_library(
    name = "bv",
    srcs = [
        "aabb.cc",
        "obb.cc",
    ],
    hdrs = [
        "aabb.h",
        "obb.h",
    ],
    deps = [
        ":boxes_overlap",
        ":posed_half_space",
        ":triangle_surface_mesh",
        ":volume_mesh",
        "//common:essential",
        "//geometry:shape_specification",
        "//geometry:utilities",
        "//math:geometric_transform",
    ],
)

drake_cc_library(
    name = "bvh",
    srcs = ["bvh.cc"],
    hdrs = ["bvh.h"],
    deps = [
        ":bv",
        ":posed_half_space",
        ":triangle_surface_mesh",
        ":volume_mesh",
        "//common:essential",
        "//geometry:shape_specification",
        "//geometry:utilities",
        "//math:geometric_transform",
    ],
)

drake_cc_library(
    name = "bvh_updater",
    hdrs = ["bvh_updater.h"],
    deps = [
        ":bv",
        ":bvh",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "calc_distance_to_surface_mesh",
    srcs = ["calc_distance_to_surface_mesh.cc"],
    hdrs = ["calc_distance_to_surface_mesh.h"],
    internal = True,
    visibility = ["//visibility:private"],
    deps = [
        ":bv",
        ":bvh",
        ":triangle_surface_mesh",
        "//common:essential",
    ],
    implementation_deps = [
        ":distance_to_point_callback",
        "//math:geometric_transform",
    ],
)

drake_cc_library(
    name = "calc_obb",
    srcs = ["calc_obb.cc"],
    hdrs = ["calc_obb.h"],
    deps = [
        ":bv",
        "//common:essential",
        "//geometry:shape_specification",
    ],
)

drake_cc_library(
    name = "collision_filter",
    srcs = ["collision_filter.cc"],
    hdrs = ["collision_filter.h"],
    deps = [
        "//common:essential",
        "//common:unused",
        "//geometry:collision_filter_declaration",
        "//geometry:geometry_ids",
    ],
)

drake_cc_library(
    name = "collisions_exist_callback",
    srcs = ["collisions_exist_callback.cc"],
    hdrs = ["collisions_exist_callback.h"],
    internal = True,
    visibility = [
        "//geometry:__pkg__",
    ],
    deps = [
        ":collision_filter",
        ":proximity_utilities",
        "//common:drake_export",
        "//geometry:geometry_ids",
        "@fcl_internal//:fcl",
    ],
)

drake_cc_library(
    name = "contact_surface_utility",
    srcs = ["contact_surface_utility.cc"],
    hdrs = ["contact_surface_utility.h"],
    deps = [
        ":mesh_field",
        ":polygon_surface_mesh",
        ":triangle_surface_mesh",
        "//common:default_scalars",
    ],
)

drake_cc_library(
    name = "deformable_contact_geometries",
    srcs = ["deformable_contact_geometries.cc"],
    hdrs = ["deformable_contact_geometries.h"],
    deps = [
        ":calc_distance_to_surface_mesh",
        ":hydroelastic_internal",
        ":triangle_surface_mesh",
        "//common:copyable_unique_ptr",
        "//common:essential",
        "//geometry:deformable_mesh_with_bvh",
        "//geometry:geometry_ids",
        "//geometry:proximity_properties",
        "//geometry:shape_specification",
    ],
)

drake_cc_library(
    name = "deformable_contact_internal",
    srcs = ["deformable_contact_internal.cc"],
    hdrs = ["deformable_contact_internal.h"],
    deps = [
        ":collision_filter",
        ":deformable_field_intersection",
        ":deformable_mesh_intersection",
        "//common:essential",
        "//geometry:geometry_ids",
        "//geometry:geometry_instance",
        "//geometry:shape_specification",
        "//geometry/query_results:deformable_contact",
    ],
)

drake_cc_library(
    name = "deformable_field_intersection",
    srcs = ["deformable_field_intersection.cc"],
    hdrs = ["deformable_field_intersection.h"],
    deps = [
        ":deformable_contact_geometries",
        ":field_intersection",
        ":mesh_field",
        "//geometry:geometry_ids",
        "//geometry/query_results:deformable_contact",
    ],
)

drake_cc_library(
    name = "deformable_mesh_intersection",
    srcs = ["deformable_mesh_intersection.cc"],
    hdrs = ["deformable_mesh_intersection.h"],
    deps = [
        ":bvh",
        ":deformable_contact_geometries",
        ":mesh_intersection",
        ":triangle_surface_mesh",
        "//geometry:deformable_mesh_with_bvh",
        "//geometry/query_results:deformable_contact",
        "//math:geometric_transform",
    ],
)

drake_cc_library(
    name = "detect_zero_simplex",
    srcs = ["detect_zero_simplex.cc"],
    hdrs = ["detect_zero_simplex.h"],
    deps = [
        ":volume_mesh",
        ":volume_to_surface_mesh",
        "//common:sorted_pair",
    ],
)

drake_cc_library(
    name = "distance_to_point_callback",
    srcs = [
        "calc_signed_distance_to_surface_mesh.cc",
        "distance_to_point_callback.cc",
        "mesh_distance_boundary.cc",
    ],
    hdrs = [
        "calc_signed_distance_to_surface_mesh.h",
        "distance_to_point_callback.h",
        "mesh_distance_boundary.h",
    ],
    internal = True,
    visibility = [
        "//geometry:__pkg__",
    ],
    deps = [
        ":bv",
        ":bvh",
        ":proximity_utilities",
        ":triangle_surface_mesh",
        ":volume_mesh",
        ":volume_to_surface_mesh",
        "//common:default_scalars",
        "//common:drake_export",
        "//common:essential",
        "//geometry:geometry_ids",
        "//geometry/query_results:signed_distance_to_point",
        "//math:geometric_transform",
        "@fcl_internal//:fcl",
    ],
)

drake_cc_library(
    name = "distance_to_shape_callback",
    srcs = ["distance_to_shape_callback.cc"],
    hdrs = ["distance_to_shape_callback.h"],
    internal = True,
    visibility = [
        "//geometry:__pkg__",
    ],
    deps = [
        ":collision_filter",
        ":distance_to_point_callback",
        ":distance_to_shape_touching",
        ":proximity_utilities",
        "//common:default_scalars",
        "//common:drake_export",
        "//common:nice_type_name",
        "//geometry/query_results:signed_distance_pair",
    ],
)

drake_cc_library(
    name = "distance_to_shape_touching",
    srcs = ["distance_to_shape_touching.cc"],
    hdrs = ["distance_to_shape_touching.h"],
    internal = True,
    visibility = [
        "//geometry:__pkg__",
    ],
    deps = [
        "//common:drake_export",
        "//common:essential",
        "//math:geometric_transform",
        "@fcl_internal//:fcl",
    ],
)

drake_cc_library(
    name = "field_intersection",
    srcs = ["field_intersection.cc"],
    hdrs = ["field_intersection.h"],
    deps = [
        ":bvh",
        ":contact_surface_utility",
        ":hydroelastic_internal",
        ":mesh_field",
        ":mesh_intersection",
        ":mesh_plane_intersection",
        ":plane",
        ":posed_half_space",
        ":triangle_surface_mesh",
        ":volume_mesh_topology",
        ":volume_to_surface_mesh",
        "//common:default_scalars",
        "//geometry/query_results:contact_surface",
    ],
)

drake_cc_library(
    name = "find_collision_candidates_callback",
    srcs = ["find_collision_candidates_callback.cc"],
    hdrs = ["find_collision_candidates_callback.h"],
    internal = True,
    visibility = [
        "//geometry:__pkg__",
    ],
    deps = [
        ":collision_filter",
        ":proximity_utilities",
        "//common:drake_export",
        "//common:sorted_pair",
        "@fcl_internal//:fcl",
        "@fmt",
    ],
)

drake_cc_library(
    name = "hydroelastic_calculator",
    srcs = ["hydroelastic_calculator.cc"],
    hdrs = ["hydroelastic_calculator.h"],
    internal = True,
    visibility = [
        "//geometry:__pkg__",
        "//geometry/benchmarking:__pkg__",
    ],
    deps = [
        ":field_intersection",
        ":hydroelastic_internal",
        ":mesh_half_space_intersection",
        ":mesh_intersection",
        ":mesh_plane_intersection",
        ":penetration_as_point_pair_callback",
        ":proximity_utilities",
        ":triangle_surface_mesh",
        ":volume_mesh",
        "//common:drake_export",
        "//common:hash",
        "//geometry:proximity_properties",
        "//geometry/query_results:contact_surface",
        "//math:geometric_transform",
    ],
)

drake_cc_library(
    name = "hydroelastic_internal",
    srcs = ["hydroelastic_internal.cc"],
    hdrs = ["hydroelastic_internal.h"],
    deps = [
        ":bvh",
        ":inflate_mesh",
        ":make_box_field",
        ":make_box_mesh",
        ":make_capsule_field",
        ":make_capsule_mesh",
        ":make_convex_field",
        ":make_convex_hull_mesh_impl",
        ":make_convex_mesh",
        ":make_cylinder_field",
        ":make_cylinder_mesh",
        ":make_ellipsoid_field",
        ":make_ellipsoid_mesh",
        ":make_mesh_field",
        ":make_mesh_from_vtk",
        ":make_sphere_field",
        ":make_sphere_mesh",
        ":obj_to_surface_mesh",
        ":polygon_to_triangle_mesh",
        ":tessellation_strategy",
        ":triangle_surface_mesh",
        ":volume_mesh",
        ":volume_mesh_topology",
        ":volume_to_surface_mesh",
        "//common:copyable_unique_ptr",
        "//common:essential",
        "//geometry:geometry_ids",
        "//geometry:geometry_roles",
        "//geometry:proximity_properties",
        "//geometry:shape_specification",
        "@fmt",
    ],
)

drake_cc_library(
    name = "inflate_mesh",
    srcs = ["inflate_mesh.cc"],
    hdrs = ["inflate_mesh.h"],
    deps = [
        ":volume_mesh",
    ],
    implementation_deps = [
        ":volume_to_surface_mesh",
        "//common:essential",
        "//solvers:choose_best_solver",
        "//solvers:clarabel_solver",
        "//solvers:mathematical_program",
        "//solvers:mathematical_program_result",
        "//solvers:osqp_solver",
    ],
)

drake_cc_library(
    name = "make_box_field",
    srcs = ["make_box_field.cc"],
    hdrs = ["make_box_field.h"],
    deps = [
        ":mesh_field",
        "//geometry:shape_specification",
    ],
    implementation_deps = [
        ":distance_to_point_callback",
        "//common:default_scalars",
        "//common:essential",
        "//common:unused",
    ],
)

drake_cc_library(
    name = "make_box_mesh",
    srcs = ["make_box_mesh.cc"],
    hdrs = ["make_box_mesh.h"],
    deps = [
        ":triangle_surface_mesh",
        ":volume_mesh",
        ":volume_to_surface_mesh",
        "//geometry:shape_specification",
    ],
    implementation_deps = [
        ":proximity_utilities",
        "//common:default_scalars",
    ],
)

drake_cc_library(
    name = "make_capsule_field",
    hdrs = ["make_capsule_field.h"],
    deps = [
        ":mesh_field",
        "//common:essential",
        "//common:unused",
        "//geometry:shape_specification",
    ],
)

drake_cc_library(
    name = "make_capsule_mesh",
    srcs = ["make_capsule_mesh.cc"],
    hdrs = ["make_capsule_mesh.h"],
    deps = [
        ":triangle_surface_mesh",
        ":volume_mesh",
        ":volume_to_surface_mesh",
        "//common:essential",
        "//geometry:shape_specification",
    ],
    implementation_deps = [
        ":meshing_utilities",
        ":proximity_utilities",
        "//common:default_scalars",
    ],
)

drake_cc_library(
    name = "make_convex_field",
    hdrs = ["make_convex_field.h"],
    deps = [
        ":mesh_field",
    ],
)

drake_cc_library(
    name = "make_convex_hull_mesh_impl",
    srcs = ["make_convex_hull_mesh_impl.cc"],
    hdrs = ["make_convex_hull_mesh_impl.h"],
    internal = True,
    visibility = ["//geometry:__subpackages__"],
    deps = [
        "//geometry:mesh_source",
        "//geometry/proximity:polygon_surface_mesh",
    ],
    implementation_deps = [
        ":volume_mesh",
        ":vtk_to_volume_mesh",
        "//common:diagnostic_policy",
        "//common:essential",
        "//common:find_resource",
        "//geometry:read_gltf_to_memory",
        "//geometry:read_obj",
        "//geometry:vtk_gltf_uri_loader",
        "//math:geometric_transform",
        "//systems/sensors:vtk_diagnostic_event_observer",
        "//tools/workspace/vtk_internal:vtk_opengl_init",
        "@qhull_internal//:qhull",
        "@vtk_internal//:vtkCommonCore",
        "@vtk_internal//:vtkIOGeometry",
        "@vtk_internal//:vtkRenderingCore",
    ],
)

drake_cc_library(
    name = "make_convex_hull_mesh",
    srcs = ["make_convex_hull_mesh.cc"],
    hdrs = ["make_convex_hull_mesh.h"],
    deps = [
        "//geometry:shape_specification",
        "//geometry/proximity:polygon_surface_mesh",
    ],
    implementation_deps = [
        ":make_convex_hull_mesh_impl",
    ],
)

drake_cc_library(
    name = "make_convex_mesh",
    srcs = ["make_convex_mesh.cc"],
    hdrs = ["make_convex_mesh.h"],
    deps = [
        ":volume_mesh",
        "//geometry:shape_specification",
    ],
    implementation_deps = [
        ":obj_to_surface_mesh",
        ":polygon_to_triangle_mesh",
        ":triangle_surface_mesh",
        "//common:default_scalars",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "make_cylinder_field",
    srcs = ["make_cylinder_field.cc"],
    hdrs = ["make_cylinder_field.h"],
    deps = [
        ":mesh_field",
        "//geometry:shape_specification",
    ],
    implementation_deps = [
        ":distance_to_point_callback",
        ":volume_to_surface_mesh",
        "//common:default_scalars",
        "//common:essential",
        "//common:unused",
    ],
)

drake_cc_library(
    name = "make_cylinder_mesh",
    srcs = ["make_cylinder_mesh.cc"],
    hdrs = ["make_cylinder_mesh.h"],
    deps = [
        ":triangle_surface_mesh",
        ":volume_mesh",
        ":volume_to_surface_mesh",
        "//common:essential",
        "//geometry:shape_specification",
    ],
    implementation_deps = [
        ":meshing_utilities",
        ":proximity_utilities",
        "//common:default_scalars",
    ],
)

drake_cc_library(
    name = "make_ellipsoid_field",
    hdrs = ["make_ellipsoid_field.h"],
    deps = [
        ":mesh_field",
        "//common:essential",
        "//geometry:shape_specification",
    ],
)

drake_cc_library(
    name = "make_ellipsoid_mesh",
    hdrs = ["make_ellipsoid_mesh.h"],
    deps = [
        ":make_sphere_mesh",
        ":triangle_surface_mesh",
        ":volume_mesh",
        ":volume_to_surface_mesh",
        "//geometry:shape_specification",
    ],
)

drake_cc_library(
    name = "make_mesh_field",
    srcs = ["make_mesh_field.cc"],
    hdrs = ["make_mesh_field.h"],
    deps = [
        ":calc_distance_to_surface_mesh",
        ":mesh_field",
        ":triangle_surface_mesh",
        ":volume_to_surface_mesh",
    ],
)

drake_cc_library(
    name = "make_mesh_from_vtk",
    srcs = ["make_mesh_from_vtk.cc"],
    hdrs = ["make_mesh_from_vtk.h"],
    deps = [
        ":volume_mesh",
        ":vtk_to_volume_mesh",
        "//geometry:shape_specification",
    ],
)

drake_cc_library(
    name = "make_sphere_field",
    hdrs = ["make_sphere_field.h"],
    deps = [
        ":mesh_field",
        "//common:essential",
        "//geometry:shape_specification",
    ],
)

drake_cc_library(
    name = "make_sphere_mesh",
    hdrs = ["make_sphere_mesh.h"],
    deps = [
        ":tessellation_strategy",
        ":triangle_surface_mesh",
        ":volume_mesh",
        ":volume_to_surface_mesh",
        "//common:sorted_pair",
        "//geometry:shape_specification",
    ],
)

drake_cc_library(
    name = "mesh_field",
    srcs = [
        "polygon_surface_mesh_field.cc",
        "triangle_surface_mesh_field.cc",
        "volume_mesh_field.cc",
    ],
    hdrs = [
        "mesh_field_linear.h",
        "polygon_surface_mesh_field.h",
        "triangle_surface_mesh_field.h",
        "volume_mesh_field.h",
    ],
    deps = [
        ":mesh_traits",
        ":polygon_surface_mesh",
        ":triangle_surface_mesh",
        ":volume_mesh",
        "//common:nice_type_name",
        "//common:reset_on_copy",
        "//common:sorted_pair",
    ],
)

drake_cc_library(
    name = "mesh_half_space_intersection",
    srcs = ["mesh_half_space_intersection.cc"],
    hdrs = [
        "mesh_half_space_intersection.h",
    ],
    deps = [
        ":bvh",
        ":contact_surface_utility",
        ":posed_half_space",
        ":triangle_surface_mesh",
        "//common:default_scalars",
        "//common:essential",
        "//geometry:geometry_ids",
        "//geometry:utilities",
        "//geometry/query_results:contact_surface",
    ],
)

drake_cc_library(
    name = "mesh_intersection",
    srcs = ["mesh_intersection.cc"],
    hdrs = ["mesh_intersection.h"],
    deps = [
        ":bvh",
        ":contact_surface_utility",
        ":mesh_field",
        ":posed_half_space",
        ":triangle_surface_mesh",
        ":volume_mesh",
        "//common:default_scalars",
        "//common:essential",
        "//geometry/query_results:contact_surface",
        "//math:geometric_transform",
    ],
)

drake_cc_library(
    name = "mesh_plane_intersection",
    srcs = ["mesh_plane_intersection.cc"],
    hdrs = ["mesh_plane_intersection.h"],
    deps = [
        ":bvh",
        ":contact_surface_utility",
        ":mesh_field",
        ":plane",
        ":volume_mesh",
        "//common:default_scalars",
        "//geometry/query_results:contact_surface",
        "//math:geometric_transform",
    ],
)

drake_cc_library(
    name = "mesh_to_vtk",
    srcs = ["mesh_to_vtk.cc"],
    hdrs = ["mesh_to_vtk.h"],
    deps = [
        ":mesh_field",
        ":triangle_surface_mesh",
        ":volume_mesh",
        "@fmt",
    ],
)

drake_cc_library(
    name = "mesh_traits",
    hdrs = ["mesh_traits.h"],
    deps = ["//common:autodiff"],
)

drake_cc_library(
    name = "meshing_utilities",
    srcs = ["meshing_utilities.cc"],
    hdrs = ["meshing_utilities.h"],
    deps = [
        ":triangle_surface_mesh",
        ":volume_mesh",
    ],
)

drake_cc_library(
    name = "obj_to_surface_mesh",
    srcs = ["obj_to_surface_mesh.cc"],
    hdrs = ["obj_to_surface_mesh.h"],
    deps = [
        ":triangle_surface_mesh",
        "//common:diagnostic_policy",
        "//geometry:mesh_source",
    ],
    implementation_deps = [
        "//common:essential",
        "//geometry:read_obj",
    ],
)

drake_cc_library(
    name = "penetration_as_point_pair_callback",
    srcs = ["penetration_as_point_pair_callback.cc"],
    hdrs = ["penetration_as_point_pair_callback.h"],
    internal = True,
    visibility = [
        "//geometry:__pkg__",
    ],
    deps = [
        ":collision_filter",
        ":distance_to_point_callback",
        "//common:default_scalars",
        "//common:drake_export",
        "//common:nice_type_name",
        "//geometry/query_results:penetration_as_point_pair",
        "//geometry/query_results:signed_distance_to_point",
        "@fcl_internal//:fcl",
    ],
)

drake_cc_library(
    name = "plane",
    hdrs = ["plane.h"],
    deps = [
        ":mesh_traits",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "polygon_surface_mesh",
    srcs = ["polygon_surface_mesh.cc"],
    hdrs = ["polygon_surface_mesh.h"],
    deps = [
        ":mesh_traits",
        "//math:geometric_transform",
    ],
)

drake_cc_library(
    name = "polygon_to_triangle_mesh",
    srcs = ["polygon_to_triangle_mesh.cc"],
    hdrs = ["polygon_to_triangle_mesh.h"],
    deps = [
        ":polygon_surface_mesh",
        ":triangle_surface_mesh",
    ],
)

drake_cc_library(
    name = "posed_half_space",
    hdrs = ["posed_half_space.h"],
    deps = [
        ":plane",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "proximity_utilities",
    srcs = ["proximity_utilities.cc"],
    hdrs = ["proximity_utilities.h"],
    internal = True,
    visibility = [
        "//geometry:__pkg__",
        # TODO(jwnimmer-tri) As with **every single file ever** that is named
        # "utilities", here we have too much completely unrelated code shoved
        # into one place with no rhyme nor reason, leading to dependency graph
        # nightmares. Thus, we need a visibility wart here for now.
        "//multibody/fixed_fem/dev:__pkg__",
    ],
    deps = [
        ":mesh_field",
        ":sorted_triplet",
        ":volume_mesh",
        "//common:drake_export",
        "//common:sorted_pair",
        "//geometry:geometry_ids",
        "//geometry:shape_specification",
        "@fcl_internal//:fcl",
        "@fmt",
    ],
)

drake_cc_library(
    name = "pressure_field_invariants",
    testonly = 1,
    srcs = ["test/pressure_field_invariants.cc"],
    hdrs = ["test/pressure_field_invariants.h"],
    visibility = ["//visibility:private"],
    deps = [
        ":mesh_field",
        ":triangle_surface_mesh",
        ":volume_mesh",
        ":volume_to_surface_mesh",
        "//common:essential",
        "//math:geometric_transform",
        "@googletest//:gtest_for_library",
    ],
)

drake_cc_library(
    name = "sorted_triplet",
    srcs = ["sorted_triplet.cc"],
    hdrs = ["sorted_triplet.h"],
    deps = [
        "//common:essential",
        "//common:is_less_than_comparable",
    ],
)

drake_cc_library(
    name = "tessellation_strategy",
    hdrs = ["tessellation_strategy.h"],
)

drake_cc_library(
    name = "triangle_surface_mesh",
    srcs = ["triangle_surface_mesh.cc"],
    hdrs = ["triangle_surface_mesh.h"],
    deps = [
        ":mesh_traits",
        "//math:geometric_transform",
    ],
)

drake_cc_library(
    name = "volume_mesh",
    srcs = [
        "volume_mesh.cc",
    ],
    hdrs = [
        "volume_mesh.h",
        "volume_mesh_field.h",
    ],
    deps = [
        ":mesh_traits",
        "//common:default_scalars",
        "//geometry:geometry_ids",
        "//math:geometric_transform",
        "//math:linear_solve",
    ],
)

drake_cc_library(
    name = "volume_mesh_topology",
    srcs = [
        "volume_mesh_topology.cc",
    ],
    hdrs = [
        "volume_mesh_topology.h",
    ],
    deps = [
        ":sorted_triplet",
        ":volume_mesh",
    ],
)

drake_cc_library(
    name = "volume_mesh_refiner",
    srcs = ["volume_mesh_refiner.cc"],
    hdrs = ["volume_mesh_refiner.h"],
    deps = [
        ":detect_zero_simplex",
        ":mesh_to_vtk",
        ":volume_mesh",
        ":vtk_to_volume_mesh",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "volume_to_surface_mesh",
    srcs = [
        "volume_to_surface_mesh.cc",
    ],
    hdrs = [
        "volume_to_surface_mesh.h",
    ],
    deps = [
        ":sorted_triplet",
        ":triangle_surface_mesh",
        ":volume_mesh",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "vtk_to_volume_mesh",
    srcs = [
        "vtk_to_volume_mesh.cc",
    ],
    hdrs = [
        "vtk_to_volume_mesh.h",
    ],
    deps = [
        ":volume_mesh",
        "//common:essential",
        "//geometry:mesh_source",
    ],
    implementation_deps = [
        "@fmt",
        "@vtk_internal//:vtkCommonCore",
        "@vtk_internal//:vtkCommonDataModel",
        "@vtk_internal//:vtkIOLegacy",
    ],
)

drake_cc_binary(
    name = "refine_mesh",
    srcs = ["refine_mesh.cc"],
    deps = [
        ":mesh_to_vtk",
        ":volume_mesh_refiner",
        ":vtk_to_volume_mesh",
        "//common:add_text_logging_gflags",
        "@gflags",
    ],
)

drake_cc_binary(
    name = "zero_simplex_manual_test",
    testonly = 1,
    srcs = ["test/zero_simplex_manual_test.cc"],
    add_test_rule = 1,
    data = [
        "//geometry:test_vtk_files",
    ],
    test_rule_args = [
        "--expect_fail",
        "geometry/test/one_tetrahedron.vtk",
    ],
    deps = [
        ":detect_zero_simplex",
        ":vtk_to_volume_mesh",
        "//common:add_text_logging_gflags",
        "@gflags",
    ],
)

drake_cc_googletest(
    name = "aabb_test",
    deps = [
        ":bv",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "boxes_overlap_test",
    deps = [
        ":boxes_overlap",
        "//common:hwy_dynamic",
        "//common/test_utilities:maybe_pause_for_user",
        "//geometry:meshcat",
        "//geometry:rgba",
        "//geometry:shape_specification",
        "//geometry/test_utilities:boxes_overlap_transforms",
        "@highway_internal//:hwy_test_util",
    ],
)

drake_cc_googletest(
    name = "bvh_test",
    deps = [
        ":bvh",
        ":make_ellipsoid_mesh",
        ":make_sphere_mesh",
        ":triangle_surface_mesh",
        ":volume_mesh",
        "//common/test_utilities:eigen_matrix_compare",
        "//geometry:shape_specification",
    ],
)

drake_cc_googletest(
    name = "bvh_updater_test",
    deps = [
        ":bvh",
        ":bvh_updater",
        ":make_sphere_mesh",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "calc_distance_to_surface_mesh_test",
    deps = [
        ":calc_distance_to_surface_mesh",
        ":make_box_mesh",
    ],
)

drake_cc_googletest(
    name = "calc_obb_test",
    data = [
        "//geometry:test_obj_files",
    ],
    deps = [
        ":calc_obb",
        "//common:find_resource",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "calc_signed_distance_to_surface_mesh_test",
    deps = [
        ":distance_to_point_callback",
        ":volume_mesh",
        ":volume_to_surface_mesh",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_library(
    name = "characterization_utilities",
    testonly = 1,
    srcs = ["test/characterization_utilities.cc"],
    hdrs = ["test/characterization_utilities.h"],
    visibility = ["//visibility:private"],
    deps = [
        ":collision_filter",
        "//common:drake_export",
        "//common:temp_directory",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "//geometry:proximity_engine",
        "//geometry:utilities",
        "//geometry/proximity:proximity_utilities",
        "//math:geometric_transform",
        "@fcl_internal//:fcl",
    ],
)

drake_cc_googletest(
    name = "characterization_utilities_test",
    deps = [":characterization_utilities"],
)

drake_cc_googletest(
    name = "collision_filter_test",
    deps = [
        ":collision_filter",
    ],
)

drake_cc_googletest(
    name = "collisions_exist_callback_test",
    deps = [
        ":collisions_exist_callback",
    ],
)

drake_cc_googletest(
    name = "contact_surface_test",
    deps = [
        "//common/test_utilities:eigen_matrix_compare",
        "//geometry:geometry_ids",
        "//geometry/query_results:contact_surface",
    ],
)

drake_cc_googletest(
    name = "contact_surface_utility_test",
    deps = [
        ":contact_surface_utility",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "//math:autodiff",
    ],
)

drake_cc_googletest(
    name = "deformable_contact_geometries_test",
    deps = [
        ":deformable_contact_geometries",
        ":make_box_mesh",
        ":make_sphere_mesh",
        "//common/test_utilities:expect_no_throw",
        "//common/test_utilities:expect_throws_message",
        "//geometry:proximity_properties",
    ],
)

drake_cc_googletest(
    name = "deformable_contact_internal_test",
    data = [
        "//geometry:test_obj_files",
    ],
    deps = [
        ":deformable_contact_internal",
        ":make_box_mesh",
        ":make_sphere_mesh",
        "//common:find_resource",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_no_throw",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "deformable_field_intersection_test",
    deps = [
        ":deformable_field_intersection",
        ":make_box_mesh",
        ":volume_mesh",
    ],
)

drake_cc_googletest(
    name = "deformable_mesh_intersection_test",
    deps = [
        ":deformable_mesh_intersection",
        ":make_box_mesh",
        ":make_sphere_mesh",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "detect_zero_simplex_test",
    deps = [
        ":detect_zero_simplex",
        ":make_cylinder_mesh",
        ":mesh_to_vtk",
    ],
)

drake_cc_googletest(
    name = "distance_sphere_to_shape_test",
    deps = [
        ":distance_to_shape_callback",
        "//common/test_utilities",
        "//geometry:geometry_ids",
        "//geometry:utilities",
        "//math:gradient",
    ],
)

drake_cc_googletest(
    name = "distance_to_point_callback_test",
    deps = [
        ":distance_to_point_callback",
        "//common/test_utilities",
        "//geometry:utilities",
        "//math",
    ],
)

drake_cc_googletest(
    name = "distance_to_point_characterize_test",
    deps = [
        ":characterization_utilities",
        ":distance_to_point_callback",
        ":make_box_mesh",
    ],
)

drake_cc_googletest(
    name = "distance_to_shape_characterize_test",
    deps = [
        ":characterization_utilities",
        ":distance_to_shape_callback",
        "//common:temp_directory",
        "//geometry:proximity_engine",
        "//math:geometric_transform",
    ],
)

drake_cc_googletest(
    name = "distance_to_shape_touching_test",
    deps = [
        ":distance_to_shape_touching",
        "//common:essential",
        "//common/test_utilities",
        "//math:geometric_transform",
    ],
)

drake_cc_googletest(
    name = "field_intersection_test",
    deps = [
        ":contact_surface_utility",
        ":field_intersection",
        ":make_box_field",
        ":make_box_mesh",
        ":make_sphere_field",
        ":make_sphere_mesh",
        ":triangle_surface_mesh",
        ":volume_to_surface_mesh",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "//geometry:shape_specification",
        "//math:geometric_transform",
    ],
)

drake_cc_googletest(
    name = "find_collision_candidates_callback_test",
    deps = [
        ":find_collision_candidates_callback",
    ],
)

drake_cc_googletest(
    name = "hydroelastic_calculator_test",
    deps = [
        ":hydroelastic_calculator",
        "//common/test_utilities",
        "//math:autodiff",
    ],
)

drake_cc_googletest(
    name = "hydroelastic_internal_test",
    data = [
        "//geometry:test_gltf_files",
        "//geometry:test_obj_files",
        "//geometry:test_vtk_files",
    ],
    deps = [
        ":hydroelastic_internal",
        ":proximity_utilities",
        "//common:find_resource",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_no_throw",
        "//common/test_utilities:expect_throws_message",
        "@fmt",
    ],
)

drake_cc_googletest(
    name = "inflate_mesh_test",
    data = [
        "//geometry:test_vtk_files",
    ],
    deps = [
        ":inflate_mesh",
        ":make_mesh_from_vtk",
        ":volume_to_surface_mesh",
        "//common:find_resource",
        "//geometry:shape_specification",
    ],
)

drake_cc_googletest(
    name = "make_box_field_test",
    deps = [
        ":make_box_field",
        ":make_box_mesh",
        ":pressure_field_invariants",
        ":volume_to_surface_mesh",
    ],
)

drake_cc_googletest(
    name = "make_box_mesh_test",
    deps = [
        ":make_box_mesh",
        ":proximity_utilities",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "make_capsule_field_test",
    deps = [
        ":make_capsule_field",
        ":make_capsule_mesh",
        ":pressure_field_invariants",
        ":volume_to_surface_mesh",
    ],
)

drake_cc_googletest(
    name = "make_capsule_mesh_test",
    deps = [
        ":make_capsule_mesh",
        ":proximity_utilities",
    ],
)

drake_cc_googletest(
    name = "make_convex_field_test",
    data = [
        "//geometry:test_obj_files",
    ],
    deps = [
        ":make_convex_field",
        ":make_convex_mesh",
        ":obj_to_surface_mesh",
        ":proximity_utilities",
        ":volume_to_surface_mesh",
        "//common:find_resource",
    ],
)

drake_cc_googletest(
    name = "make_convex_hull_mesh_impl_test",
    data = [
        "//geometry:test_gltf_files",
        "//geometry:test_obj_files",
        "//geometry:test_vtk_files",
        "//geometry/render:test_models",
    ],
    deps = [
        ":make_convex_hull_mesh_impl",
        "//common:find_resource",
        "//common:memory_file",
        "//common:temp_directory",
        "//common/test_utilities:expect_throws_message",
        "@nlohmann_internal//:nlohmann",
    ],
)

drake_cc_googletest(
    name = "make_convex_hull_mesh_test",
    data = [
        "//geometry/render:test_models",
    ],
    deps = [
        ":make_convex_hull_mesh",
        "//common:find_resource",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "make_convex_mesh_test",
    data = [
        "//geometry:test_obj_files",
    ],
    deps = [
        ":make_convex_mesh",
        ":obj_to_surface_mesh",
        ":polygon_to_triangle_mesh",
        ":proximity_utilities",
        ":volume_to_surface_mesh",
        "//common:find_resource",
    ],
)

drake_cc_googletest(
    name = "make_cylinder_field_test",
    deps = [
        ":make_cylinder_field",
        ":make_cylinder_mesh",
        ":pressure_field_invariants",
        ":volume_to_surface_mesh",
    ],
)

drake_cc_googletest(
    name = "make_cylinder_mesh_test",
    shard_count = 2,
    deps = [
        ":make_cylinder_mesh",
        ":proximity_utilities",
    ],
)

drake_cc_googletest(
    name = "make_ellipsoid_field_test",
    deps = [
        ":make_ellipsoid_field",
        ":make_ellipsoid_mesh",
        ":pressure_field_invariants",
        ":volume_to_surface_mesh",
    ],
)

drake_cc_googletest(
    name = "make_ellipsoid_mesh_test",
    deps = [
        ":make_ellipsoid_mesh",
    ],
)

drake_cc_googletest(
    name = "make_mesh_field_test",
    data = [
        "//geometry:test_vtk_files",
    ],
    deps = [
        ":make_mesh_field",
        ":make_mesh_from_vtk",
        ":pressure_field_invariants",
        "//common:find_resource",
        "//common/test_utilities",
    ],
)

drake_cc_googletest(
    name = "make_mesh_from_vtk_test",
    data = [
        "//geometry:test_vtk_files",
    ],
    deps = [
        ":make_mesh_from_vtk",
        "//common:find_resource",
        "//common/test_utilities",
    ],
)

drake_cc_googletest(
    name = "make_sphere_field_test",
    deps = [
        ":make_sphere_field",
        ":make_sphere_mesh",
        ":pressure_field_invariants",
        ":volume_to_surface_mesh",
    ],
)

drake_cc_googletest(
    name = "make_sphere_mesh_test",
    deps = [
        ":make_sphere_mesh",
        "//common:sorted_pair",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "mesh_deformer_test",
    deps = [
        ":make_box_mesh",
        ":polygon_surface_mesh",
        ":triangle_surface_mesh",
        ":volume_mesh",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "mesh_distance_boundary_test",
    deps = [
        "distance_to_point_callback",
    ],
)

drake_cc_googletest(
    name = "mesh_field_linear_test",
    deps = [
        ":make_box_mesh",
        ":mesh_field",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "//math:autodiff",
        "//math:geometric_transform",
    ],
)

drake_cc_googletest(
    name = "mesh_half_space_intersection_test",
    deps = [
        ":contact_surface_utility",
        ":mesh_half_space_intersection",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "//math:autodiff",
        "//math:gradient",
    ],
)

drake_cc_googletest(
    name = "mesh_intersection_test",
    deps = [
        ":mesh_intersection",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "//math:autodiff",
        "//math:geometric_transform",
        "//math:gradient",
    ],
)

drake_cc_googletest(
    name = "mesh_plane_intersection_test",
    deps = [
        ":contact_surface_utility",
        ":mesh_plane_intersection",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "//math:autodiff",
        "//math:geometric_transform",
        "//math:gradient",
    ],
)

drake_cc_googletest(
    name = "mesh_to_vtk_test",
    deps = [
        ":make_box_field",
        ":make_box_mesh",
        ":mesh_intersection",
        ":mesh_to_vtk",
        "//common:temp_directory",
        "//geometry:shape_specification",
        "//math:geometric_transform",
    ],
)

drake_cc_googletest(
    name = "mesh_traits_test",
    deps = [
        ":mesh_traits",
    ],
)

drake_cc_googletest(
    name = "meshing_utilities_test",
    data = [
        "//geometry:test_obj_files",
    ],
    deps = [
        ":meshing_utilities",
        ":obj_to_surface_mesh",
        "//common:find_resource",
    ],
)

drake_cc_googletest(
    name = "obb_test",
    data = [
        "//geometry:test_obj_files",
    ],
    deps = [
        ":bv",
        ":make_box_mesh",
        ":make_convex_hull_mesh",
        ":make_ellipsoid_mesh",
        ":make_sphere_mesh",
        ":triangle_surface_mesh",
        ":volume_mesh",
        "//common/test_utilities:eigen_matrix_compare",
        "//geometry:shape_specification",
    ],
)

drake_cc_googletest(
    name = "obj_to_surface_mesh_test",
    data = [
        "//geometry:test_obj_files",
    ],
    deps = [
        ":obj_to_surface_mesh",
        "//common:find_resource",
        "//common/test_utilities:diagnostic_policy_test_base",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "penetration_as_point_pair_callback_test",
    deps = [
        ":penetration_as_point_pair_callback",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "//math:autodiff",
        "//math:gradient",
    ],
)

drake_cc_googletest(
    name = "penetration_as_point_pair_characterize_test",
    deps = [
        ":characterization_utilities",
        ":penetration_as_point_pair_callback",
        "//common:temp_directory",
        "//geometry:proximity_engine",
        "//math:geometric_transform",
    ],
)

drake_cc_googletest(
    name = "plane_test",
    deps = [
        ":plane",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "//math:autodiff",
    ],
)

drake_cc_googletest(
    name = "polygon_surface_mesh_test",
    deps = [
        ":polygon_surface_mesh",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "polygon_to_triangle_mesh_test",
    deps = [
        ":polygon_to_triangle_mesh",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "posed_half_space_test",
    deps = [
        ":posed_half_space",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "//math:autodiff",
    ],
)

drake_cc_googletest(
    name = "proximity_utilities_test",
    deps = [":proximity_utilities"],
)

drake_cc_googletest(
    name = "sorted_triplet_test",
    deps = [
        ":sorted_triplet",
    ],
)

drake_cc_googletest(
    name = "triangle_surface_mesh_test",
    deps = [
        ":triangle_surface_mesh",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "//math:autodiff",
        "//math:geometric_transform",
    ],
)

drake_cc_googletest(
    name = "volume_mesh_refiner_test",
    deps = [
        ":mesh_to_vtk",
        ":volume_mesh_refiner",
    ],
)

drake_cc_googletest(
    name = "volume_mesh_test",
    deps = [
        ":mesh_field",
        ":volume_mesh",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "//math:autodiff",
        "//math:geometric_transform",
    ],
)

drake_cc_googletest(
    name = "volume_mesh_topology_test",
    deps = [
        ":volume_mesh_topology",
    ],
)

drake_cc_googletest(
    name = "volume_to_surface_mesh_test",
    deps = [
        ":make_box_mesh",
        ":volume_to_surface_mesh",
    ],
)

drake_cc_googletest(
    name = "vtk_to_volume_mesh_test",
    data = [
        "//geometry:test_obj_files",
        "//geometry:test_vtk_files",
    ],
    deps = [
        ":vtk_to_volume_mesh",
        "//common:find_resource",
        "//common/test_utilities",
    ],
)

drake_py_unittest(
    name = "refine_mesh_test",
    data = [
        ":refine_mesh",
        "//geometry:test_vtk_files",
    ],
    deps = [
        "@rules_python//python/runfiles",
    ],
)

add_lint_tests()
